package com.yanqu.road.entity.log;

import com.alibaba.fastjson.JSONObject;
import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.entity.log.maidian.BaseLogEntity;
import com.yanqu.road.entity.player.UserVehicleBone;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Date;

@FieldTypeAnnotation(tableName = "t_l_ck_vehicle_bone_equip", autoSave = true, desc = "珍兽魂骨装卸", uploadCk = true)
public class LogVehicleBoneEquip extends ServerBaseLog {
    @FieldTypeAnnotation(desc = "玩家ID", isIndex = true)
    private long userId;
    @FieldTypeAnnotation(desc = "珍兽唯一id")
    private String vehicleUid;
    @FieldTypeAnnotation(desc = "珍兽配置id")
    private int vehicleId;
    @FieldTypeAnnotation(desc = "装配前魂骨", saveJson = true)
    private JSONObject beforeEquip;
    @FieldTypeAnnotation(desc = "装备后魂骨", saveJson = true)
    private JSONObject afterEquip;
    @FieldTypeAnnotation(desc = "共鸣加资质")
    private int combineQuality;
    @FieldTypeAnnotation(desc = "时间")
    private Date logTime;

    public LogVehicleBoneEquip(long userId, String vehicleUid, int vehicleId, JSONObject beforeEquip, JSONObject afterEquip, int combineQuality) {
        this.userId = userId;
        this.vehicleUid = vehicleUid;
        this.vehicleId = vehicleId;
        this.beforeEquip = beforeEquip;
        this.afterEquip = afterEquip;
        this.combineQuality = combineQuality;
        this.logTime = new Date();
    }

    @Override
    public long getUserId() {
        return userId;
    }

    public static JSONObject parseEquipObject(UserVehicleBone userVehicleBone) {
//        {槽位id，魂骨id，魂骨uid，[技能id=等级,技能id=等级,]}
//        {id：数值，soulid：数值，soulpid：字符串，skill：列表}
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", userVehicleBone.getEquipPos());
        jsonObject.put("soulpid", userVehicleBone.getBoneId());
        jsonObject.put("soulid", userVehicleBone.getConfigId());
        jsonObject.put("skill", PropertyHelper.parseMapToPropertyString(userVehicleBone.getSkillMap()));

        return jsonObject;
    }
}
